import moment from 'moment';
import axios from '../axios';
import fetch from "../config/fetch";
const dataToPramas = (data) => Object.entries(data).map(item => item.join("=")).join("&")

// 格式化日期
const formatDate = date => moment(date).format('YYYY-MM-DD')
// 食品列表
export const foodCount = () => axios.get("/shopping/v2/foods/count")
export const foodList = (data) => axios.get("/shopping/v2/foods?" + dataToPramas(data))

// 订单列表
export const orderCount = () => axios.get("/bos/orders/count")
export const orderList = (data) => axios.get("/bos/orders?" + dataToPramas(data))

// 管理员列表
export const adminCount = () => axios.get("/admin/count")
export const adminList = (data) => axios.get("/admin/all?" + dataToPramas(data))

//食品分类
export const foodClass = () => axios.get("/v2/index_entry")

//获取商品列表分类
export const getRestClass = () => axios.get("/shopping/v2/restaurant/category")

// 更新食品
export const updataList = data => axios.post("/shopping/v2/updatefood", data)

export const updateFood = data => fetch('/shopping/v2/updatefood', data, 'POST');
// 删除食品
export const deleteFood = (id) => fetch('/shopping/v2/food/' + id, {}, 'DELETE');

// 登录和注册
export const doLogin = data => axios.post('/admin/login', data)

// 某一天新增用户量
export const getDayUserCount = date => axios.get(`/statis/user/${formatDate(date)}/count`)

// 某一天新增订单量
export const getDayOrderCount = date => axios.get(`/statis/order/${formatDate(date)}/count`)

// 某一天管理员注册量
export const getDayAdminCount = date => axios.get(`/statis/admin/${formatDate(date)}/count`)

// 获取用户数量
export const getUserCount = () => axios.get('/v1/users/count')

// 获取订单数量
export const getOrderCount = () => axios.get('/bos/orders/count')

// 获取管理员数量
export const getAdminCount = () => axios.get('admin/count')

// 获取用户列表
export const getUserList = data => axios.get('/v1/users/list?' + dataToPramas(data))

// 更新店铺
export const upDateRest = data => fetch('/shopping/updateshop', data, 'POST');

// 获取餐馆数量
export const getRestCount = () => axios.get('/shopping/restaurants/count')

export const getRestList = data => axios.get('/shopping/restaurants?latitude=23.12497&longitude=113.26308&' + dataToPramas(data))

// 删除店铺
export const deleteRest = id => fetch('/shopping/restaurant/' + id, {}, 'DELETE');

// 获取用户信息
export const getUser = () => fetch('/admin/info')

// 请求商铺分类列表
export const getCategoryList = () => axios.get('/shopping/v2/restaurant/category')

// 获取当前店铺食品分类
export const getRestFoodsClass = (id) => axios.get('/shopping/getcategory/' + id)

// 添加食品种类
export const addFoodsClass = data => fetch('/shopping/addcategory', data, 'POST');

// 添加食品
export const addFoodsApi = data => fetch('/shopping/addfood', data, 'POST');

// 添加商铺
export const addRest = data => fetch('/shopping/addShop', data, 'POST');

